package com.cse210.grocerwe.server;

import java.io.File;

import org.restlet.Application;
import org.restlet.Restlet;
import org.restlet.data.Protocol;
import org.restlet.data.LocalReference;
import org.restlet.resource.Directory;
import org.restlet.routing.Router;
import org.restlet.Component;

public class TestServerApplication extends Application {
    
    /**
     * When launched as a standalone application.
     * 
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        Component component = new Component();
        component.getClients().add(Protocol.FILE);
        component.getServers().add(Protocol.HTTP, 8080);
        component.getDefaultHost().attach(new TestServerApplication());
        component.start();
    }

	@Override
	public Restlet createInboundRoot() {
		Router router = new Router(getContext());
	    getConnectorService().getClientProtocols().add(Protocol.FILE);
	    getConnectorService().getClientProtocols().add(Protocol.CLAP);
	    
        // Serve the files generated by the GWT compilation step.
        File warDir = new File("");
        if (!"war".equals(warDir.getName())) {
            warDir = new File(warDir, "war/");
        }

        Directory dir = new Directory(getContext(), LocalReference
                .createFileReference(warDir));
        router.attachDefault(dir);
        router.attach("/android/interfaceA/{user}", APIResourceA.class);
        router.attach("/android/interfaceB/{user}", APIResourceB.class);
        router.attach("/android/interfaceC/{group}", APIResourceC.class);
        router.attach("/android/interfaceD/", APIResourceD.class);
        router.attach("/android/interfaceE/", APIResourceE.class);
        router.attach("/android/interfaceF/", APIResourceF.class);
        router.attach("/android/interfaceG/", APIResourceG.class);
        router.attach("/android/interfaceH/", APIResourceH.class);
        router.attach("/android/interfaceI/", APIResourceI.class);
        router.attach("/database",DBResource.class);

		return router;
	}

}
